﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PublSystem
{
    public partial class Keyword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string q = "";

            try
            {
                q = Request.QueryString["q"];
                
            }
            catch
            {
                q = "";
            }

            this.Page.Title = "Keyword: " + q;
            if (q != "" && q != null)
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    conn.Open();
                    SqlDataAdapter cmd = new SqlDataAdapter(@"SELECT * FROM PublicationsInfo.Publications
                                                        , PublicationsInfo.KeywordsPublications , PublicationsInfo.Keywords WHERE PublicationsInfo.KeywordsPublications.keywordId = PublicationsInfo.Keywords.keywordId 
                                                        AND PublicationsInfo.Publications.publicationId = PublicationsInfo.KeywordsPublications.publicationId
                                                        AND PublicationsInfo.Keywords.keyword LIKE '%" + q + "%'", conn);


                    DataSet ds = new DataSet();
                    cmd.Fill(ds);

                    publs.DataSource = ds;
                    publs.DataBind();
                }
        }
    }
}